﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using BbsbWebService.Classes.Controllers;
using BbsbWebService.Enums;
using System.Xml.Linq;

namespace BbsbWebService.Classes.Plugins.KeyMap
{
    [DataContract]
    public class KeyMapItem : PluginItem<KeyMapController>
    {
        /// <summary>
        /// [Optional] Gets or Sets the Id of the device
        /// </summary>
        [DataMember]
        [PluginAdditionalPropertyDescription("[Optional] The Id of the device")]
        public string DeviceId { get; set; }

        protected override string GetCommand(PowerOption option)
        {
            string retVal;
            // We don't care about the power as of yet...
            if (!DeviceId.IsNullOrEmpty())
            {
                retVal = string.Format("press_irdevice_button.asp?bid={0}&did={1}", Command, DeviceId);
            }
            else
            {
                retVal = string.Format("press_remote_button.aspx?id={0}", Command);
            }
            return retVal;
        }

        public override IEnumerable<XElement> SaveAdditionalProperties()
        {
            yield return new XElement("DeviceId", DeviceId);
        }

        public override void AddItemDependantProperty(XElement element)
        {
            this.DeviceId = element.GetChildValueFromElement<string>("DeviceId");
        }
    }
}
